﻿Public Class frmReserveRoomslc
    Private da As New DSVaultingTableAdapters.rr_reserve_roomsTableAdapter
    Private dt As DataTable
    Private dta As DataTable
    Public sample As Boolean

    Private Sub frmReserveRoomslc_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dt = da.GetBranchHasRoomOnly

        uxBranchCbx.DataSource = dt
        uxBranchCbx.DisplayMember = "LOCATION_NAME"
        uxBranchCbx.ValueMember = "BRANCH_ID"

        dta = da.GetDataByBranchID(uxBranchCbx.SelectedValue)

        uxRoomCbx.DataSource = dta
        uxRoomCbx.DisplayMember = "ROOM_NAME"
        uxRoomCbx.ValueMember = "ROOM_ID"
    End Sub

    Private Sub uxBranchCbx_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uxBranchCbx.SelectedIndexChanged
        uxBranchCbx.ValueMember = "BRANCH_ID"
        uxRoomCbx.DataSource = da.GetDataByBranchID(uxBranchCbx.SelectedValue)
        uxRoomCbx.DisplayMember = "ROOM_NAME"
        uxRoomCbx.ValueMember = "ROOM_ID"
    End Sub

    Private Sub uxRoomCbx_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uxRoomCbx.SelectedIndexChanged
        uxRoomCbx.ValueMember = "ROOM_ID"
        If isSample(uxRoomCbx.SelectedValue) Then
            uxIsSampleCbx.Enabled = True
            uxIsSampleCbx.SelectedIndex = 0
        Else
            sample = False
            uxIsSampleCbx.Text = ""
            uxIsSampleCbx.Enabled = False
        End If
    End Sub

    Private Sub uxOKBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uxOKBtn.Click
        frmReserveRooms.Show()
        Me.Close()
    End Sub

    Private Sub uxCancelBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uxCancelBtn.Click
        frmRoomSelecting.Enabled = True
        Me.Close()
    End Sub

    Private Function isSample(ByVal room_id As Integer) As Boolean
        Dim val As Integer = da.ScalarQueryIsSample(room_id)
        If val = 1 Then
            Return True
        Else
            Return False
        End If
    End Function

    Private Sub uxIsSampleCbx_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uxIsSampleCbx.SelectedIndexChanged
        If uxIsSampleCbx.SelectedIndex = 0 Then
            sample = True
        Else
            sample = False
        End If
    End Sub

    Private Sub frmReserveRoomslc_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
        frmRoomSelecting.Enabled = True
    End Sub
End Class